{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-07-05T03:28:11.906896400Z",
     "start_time": "2024-07-05T03:28:11.902835500Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "666\n",
      "13.14\n",
      "黑马程序员\n"
     ]
    }
   ],
   "source": [
    "# 字面量\n",
    "666\n",
    "13.14\n",
    "\"黑马程序员\"\n",
    "\n",
    "print(666)\n",
    "print(13.14)\n",
    "print(\"黑马程序员\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "666\n",
      "13.14\n",
      "黑马程序员\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "多行注释\n",
    "\"\"\"\n",
    "\n",
    "# 单行注释，写一个整数字面量\n",
    "print(666)\n",
    "\n",
    "\"\"\"多行注释\"\"\""
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T03:29:12.846881300Z",
     "start_time": "2024-07-05T03:29:12.834910300Z"
    }
   },
   "id": "8e80680484ec3382"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "钱包还有： 50\n",
      "买了冰淇淋花费10元，还剩余： 30 元\n",
      "现在是下午1点，钱包余额剩余： 30\n",
      "现在是下午2点，钱包余额剩余： 30\n",
      "现在是下午3点，钱包余额剩余： 30\n",
      "现在是下午4点，钱包余额剩余： 30\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "演示Python中变量的相关操作\n",
    "\"\"\"\n",
    "\n",
    "# 定义一个变量，用来记录钱包余额\n",
    "money = 50\n",
    "# 通过print语句，输出变量记录的内容\n",
    "print(\"钱包还有：\", money)\n",
    "\n",
    "# 买了一个冰淇淋，花费10元\n",
    "money = money - 20\n",
    "print(\"买了冰淇淋花费10元，还剩余：\", money, \"元\")\n",
    "\n",
    "# 假设，每隔一小时，输出一下钱包的余额\n",
    "print(\"现在是下午1点，钱包余额剩余：\", money)\n",
    "print(\"现在是下午2点，钱包余额剩余：\", money)\n",
    "print(\"现在是下午3点，钱包余额剩余：\", money)\n",
    "print(\"现在是下午4点，钱包余额剩余：\", money)\n",
    "\n",
    "Name = \"张三\"\n",
    "Age = 11"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T03:30:24.023597500Z",
     "start_time": "2024-07-05T03:30:24.012128800Z"
    }
   },
   "id": "5301b4cfb7b3e36f"
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "<class 'int'>\n",
      "<class 'float'>\n",
      "<class 'str'>\n",
      "<class 'int'>\n",
      "<class 'float'>\n",
      "True\n",
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 方式1： 使用print直接输出类型信息\n",
    "print(type(\"黑马程序员\"))\n",
    "print(type(666))\n",
    "print(type(11.345))\n",
    "\n",
    "# 方式2： 使用变量存储type()语句的结果\n",
    "string_type = type(\"黑马程序员\")\n",
    "int_type = type(666)\n",
    "float_type = type(11.345)\n",
    "print(string_type)\n",
    "print(int_type)\n",
    "print(float_type)\n",
    "print(float_type is float)  # 判断类型\n",
    "\n",
    "# 方式3： 使用type()语句，查看变量中存储的数据类型信息\n",
    "name = \"黑马程序员\"\n",
    "name_type = type(name)\n",
    "print(name_type)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T03:47:22.548366Z",
     "start_time": "2024-07-05T03:47:22.536367500Z"
    }
   },
   "id": "75bcb56b5e15b7f8"
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'> 11\n",
      "<class 'str'> 11.345\n",
      "<class 'int'> 11\n",
      "<class 'float'> 11.345\n",
      "<class 'float'> 11.0\n",
      "<class 'int'> 11\n"
     ]
    }
   ],
   "source": [
    "# 将数字类型转换成字符串\n",
    "num_str = str(11)\n",
    "print(type(num_str), num_str)\n",
    "\n",
    "float_str = str(11.345)\n",
    "print(type(float_str), float_str)\n",
    "# 将字符串转换成数字\n",
    "num = int(\"11\")\n",
    "print(type(num), num)\n",
    "\n",
    "num2 = float(\"11.345\")\n",
    "print(type(num2), num2)\n",
    "\n",
    "# 错误示例，想要将字符串转换成数字，必须要求字符串内的内容都是数字\n",
    "# num3 = int(\"黑马程序员\")\n",
    "# print(type(num3), num3)\n",
    "\n",
    "# 整数转浮点数\n",
    "float_num = float(11)\n",
    "print(type(float_num), float_num)\n",
    "\n",
    "# 浮点数转整数\n",
    "int_num = int(11.345)\n",
    "print(type(int_num), int_num)\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T09:07:38.412199800Z",
     "start_time": "2024-07-05T09:07:38.408849500Z"
    }
   },
   "id": "eba2bc8640a33176"
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "黑马程序员\n",
      "666\n"
     ]
    }
   ],
   "source": [
    "# 规则1：内容限定，限定只能使用：中文、英文、数字、下划线，注意：不能以数字开头\n",
    "# 错误的代码示范：1_name = \"张三\"\n",
    "# 错误的代码示范：name_! = \"张三\"\n",
    "name_ = \"张三\"\n",
    "_name = \"张三\"\n",
    "name_1 = \"张三\"\n",
    "\n",
    "\n",
    "# 规则2：大小写敏感\n",
    "Itheima = \"黑马程序员\"\n",
    "itheima = 666\n",
    "print(Itheima)\n",
    "print(itheima)\n",
    "\n",
    "\n",
    "# 规则3：不可使用关键字\n",
    "# 错误的示例，使用了关键字：class = 1\n",
    "# 错误的示例，使用了关键字：def = 1\n",
    "Class = 1\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T09:08:08.327395900Z",
     "start_time": "2024-07-05T09:08:08.304429800Z"
    }
   },
   "id": "e156028b29dcc6f8"
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "学IT来黑马月薪过万\n",
      "我是：黑马程序员，我的地址是：建材城东路9号院，我的电话是：4006189090\n"
     ]
    }
   ],
   "source": [
    "# 字符串字面量之间的拼接\n",
    "print(\"学IT来黑马\" + \"月薪过万\")\n",
    "# 字符串字面量和字符串变量的拼接\n",
    "name = \"黑马程序员\"\n",
    "address = \"建材城东路9号院\"\n",
    "tel = 4006189090\n",
    "print(\"我是：\" + name + \"，我的地址是：\" + address + \"，我的电话是：\" + str(tel))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-05T09:11:08.870201200Z",
     "start_time": "2024-07-05T09:11:08.859230800Z"
    }
   },
   "id": "a5247e39b629602e"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "# 通过占位的形式，完成拼接\n",
    "name = \"黑马程序员\"\n",
    "message = \"学IT来：%s\" % name\n",
    "print(message)\n",
    "\n",
    "# 通过占位的形式，完成数字和字符串的拼接\n",
    "class_num = 57\n",
    "avg_salary = 16781\n",
    "message = \"Python大数据学科，北京%s期，毕业平均工资：%s\" % (class_num, avg_salary)\n",
    "print(message)\n",
    "\n",
    "name = \"传智播客\"\n",
    "setup_year = 2006\n",
    "stock_price = 19.99\n",
    "message = \"%s，成立于：%d，我今天的股价是：%f\" % (name, setup_year, stock_price)\n",
    "print(message)\n",
    "\n",
    "\n",
    "num1 = 11\n",
    "num2 = 11.345\n",
    "print(\"数字11宽度限制5，结果是：%5d\" % num1)\n",
    "print(\"数字11宽度限制1，结果是：%1d\" % num1)\n",
    "print(\"数字11.345宽度限制7，小数精度2，结果是：%7.2f\" % num2)\n",
    "print(\"数字11.345不限制，小数精度2，结果是：%.2f\" % num2)\n"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "c8b421f13ef8ec16"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "f2a741ed5031a502"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "dae0a9f5db66d40e"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "d2094d6e9d30f104"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "c33c90a4830e926d"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "d06d0e48fee9d1c9"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "6df3fb83f981382f"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "71791982bcc00266"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "19ca570ef52c5c02"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "4bc89c632fc0b4a2"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "9db711a75173774"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "98b7e1beb1a0caaf"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
